package com.xugongzhang.autowire.config;

import com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

import javax.sql.DataSource;

/**
 * @author X
 * @date 2022/12/6 0:36
 */
@Configuration
public class MainConfigOfProfile {

    @Profile("dev")
    @Bean
    public DataSource dataSourceTest() {
        MysqlConnectionPoolDataSource dataSource = new MysqlConnectionPoolDataSource();
        dataSource.setURL("jdbc:mysql://localhost:3306/test");
        dataSource.setUser("root");
        return dataSource;
    }

    @Profile("test")
    @Bean
    public DataSource dataSourceDev() {
        MysqlConnectionPoolDataSource dataSource = new MysqlConnectionPoolDataSource();
        dataSource.setURL("jdbc:mysql://localhost:3306/test");
        dataSource.setUser("root");
        return dataSource;
    }
}
